package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.banner.DeleteBannerBo;
import com.zhuss.bean.vo.core.banner.DetailBannerVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.BannerDao;
import com.zhuss.core.db.entity.Banner;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * 删除banner processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("bannerDelete")
public class BannerDelete extends AbstractProcessor<Object, DeleteBannerBo> implements Processor<Object, DeleteBannerBo> {

    @Autowired
    private BannerDao bannerDao;
    
    @Autowired
	@Qualifier("bannerRead")
	private BannerRead bannerRead;
    
    
    @Autowired
	@Qualifier("companyRead")
	private CompanyRead companyRead;
    
    
    @Autowired
	@Qualifier("userRead")
	private UserRead userRead;
    
    
    @Autowired
	@Qualifier("roleRead")
	private RoleRead roleRead;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteBannerBo bo) throws WpsException {
    	
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteBannerBo param) throws WpsException {
    	Long bannerId = param.getBannerId();
    	String name = ((DetailBannerVo) bannerRead.detail(bannerId)).getName() + "";
    	
    	Banner record = new Banner();
    	record.setBannerId(bannerId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	bannerDao.delete(record);
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteBannerBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.banner删除.key());
    	record.setTargetId(param.getBannerId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
